var xmlHttp;
function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
} 
function showListUser()
{
	if (xmlhttp.readyState==4 && xmlhttp.status == 200)
	{
		document.getElementById("divResult").innerHTML=xmlhttp.responseText;
	}
}


function TimKiem()
{	
	var keyword = document.getElementById("txtKey").value;
	if(keyword == "")
		return false;
		
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Your browser does not support XML HTTP Request");
		return;
	}
	
	
	xmlhttp.onreadystatechange = showListUser;	
	
	var url = "../admin/user_search.php?keyword=" + keyword + "&rand=" + Math.random();
	xmlhttp.open("GET", url, true);			
	xmlhttp.send(null);
	
	return false;

}

function GoTo(page)
{
	var key = document.getElementById("txtKey").value;		
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Your browser does not support XML HTTP Request");
		return;
	}
	
	xmlhttp.onreadystatechange = showListUser;	
	var url = "../admin/user_search.php" + "?page=" + page + "&keyword=" + key + "&rand=" + Math.random();	
	xmlhttp.open("GET", url, true);	
	xmlhttp.send(null);
	
	return false;
}


var activeNode;
function Active(node, id)
{
	
	activeNode = node;
	var status;
	if(activeNode.innerHTML == "Kích hoạt")
		status = 1;
	else if(activeNode.innerHTML == "Vô hiệu")
		status = 0;
	
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Your browser does not support XML HTTP Request");
		return;
	}
	
	
	xmlhttp.onreadystatechange = showActivate;	
	
	var url = "../admin/user_active.php?id=" + id + "&status=" + status + "&rand=" + Math.random();
	xmlhttp.open("GET", url, true);			
	xmlhttp.send(null);
}

function showActivate()
{
	if (xmlhttp.readyState==4 && xmlhttp.status == 200)
	{
		if(xmlhttp.responseText == "activated")
		{			
			activeNode.innerHTML = "Vô hiệu";
		}
		else if(xmlhttp.responseText == "blocked")
		{
			activeNode.innerHTML = "Kích hoạt";
		}
		else if(xmlhttp.responseText == "failed")
		{
			alert("Cập nhật không thành công. Vui lòng cập nhật lại.");
		}			
	}
}